<template>
  <t-tabs v-model="tabValue">
    <t-tab-panel value="1" label="软著信息">
      <t-form ref="form" class="step-form" labelWidth="120px">
        <t-row style="flex: 1">
          <t-col :span="12">
            <t-form-item label="软件名称：" name="name">
              {{ objData.name }}
            </t-form-item>
            <t-form-item label="开发完成日期：" name="completeDevelopmentDate">
              {{ objData.completeDevelopmentDate }}
            </t-form-item>
            <t-form-item label="首次发表日期：" name="firstPublicationDate">
              {{ objData.firstPublicationDate }}
            </t-form-item>
            <t-form-item label="权利取得方式：" name="getWay">
              {{ objData.getWay | filterByDict(dict.type.get_way) }}
            </t-form-item>
            <t-form-item label="权利范围：" name="scopeRights">
              {{ objData.scopeRights | filterByDict(dict.type.scope_rights, '全部权利') }}
            </t-form-item>
            <t-form-item label="登记号：" name="registerNum">
              {{ objData.registerNum }}
            </t-form-item>
            <t-form-item label="填报单位：" name="declareDeptName">
              {{ objData.declareDeptName }}
            </t-form-item>
            <t-form-item label="关键词：" name="keyWord">
              {{ objData.keyWord }}
            </t-form-item>
            <t-form-item label="备注：" name="note">
              {{ objData.note }}
            </t-form-item>
          </t-col>
        </t-row>
      </t-form>
    </t-tab-panel>
    <t-tab-panel value="2" label="著作权人">
      <t-row style="align-items: stretch" :gutter="14"
        v-show="objData.copyrightMemberList && objData.copyrightMemberList.length > 0">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="个人">
            <copyright-member :objId="objId" v-model="objData.copyrightMemberList" :editOpen="false"></copyright-member>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14"
        v-show="objData.copyrightCompanyList && objData.copyrightCompanyList.length > 0">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="单位">
            <copyright-company :objId="objId" ref="copyright-company" v-model="objData.copyrightCompanyList"
              :editOpen="false"></copyright-company>
          </t-card>
        </t-col>
      </t-row>
    </t-tab-panel>
    <t-tab-panel value="3" label="年度社会、经济效益">
      <copyright-benefit :objId="objId" ref="copyright-benefit" v-model="objData.benefitList"
        :editOpen="false"></copyright-benefit>
    </t-tab-panel>
    <t-tab-panel value="4" label="著作项目来源">
      <copyright-project :objId="objId" ref="soft-project" v-model="objData.projectList"
        :editOpen="false" style="height: 58vh;width: 100%; overflow: auto; overflow-x: hidden;"></copyright-project>
    </t-tab-panel>
    <t-tab-panel value="5" label="附件信息">
      <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
        <template #id="{ row, rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <template #c1="{ row }">
          <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
          <div v-else>{{ row.c1 }}</div>
        </template>
        <template #op="{ row }">
          <div v-for="(item, index) in row.fileLists" :key="index">
            <a class="t-button-link" target="_blank" :href="item.url">
              {{ item.name }}
            </a>
          </div>
        </template>
      </t-table>
    </t-tab-panel>
  </t-tabs>
</template>

<script>
import { getFiles } from "@/api/common";
import copyrightMember from "./copyright-member.vue";
import copyrightCompany from "./copyright-company.vue";
import copyrightProject from "./copyright-project.vue";
import copyrightBenefit from "./copyright-benefit.vue";


export default {
  name: "copyright-detail",
  dicts: ['get_way', 'scope_rights'],
  components: {
    copyrightMember,
    copyrightProject,
    copyrightCompany,
    copyrightBenefit
  },
  props: {
    objId: [String, Number],
  },
  data () {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      tabValue: '1',
      objData: {
      },
      projectFileData: [
        {
          id: 1,
          c1: "软件著作权证书",
          c2: "是",
          moduleKey: "copyrightZS",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 4,
          c1: "其他",
          c2: "否",
          fileIds: [],
          fileLists: [],
          moduleKey: "copyrightOther",
          require: false
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler (val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  methods: {
    getObj () {
      // 获取项目附件
      getFiles(this.objId).then((res) => {
        const files = {}
        res.data.forEach((item) => {
          if (!files[item.moduleKey]) {
            files[item.moduleKey] = []
          }
          files[item.moduleKey].push({
            name: item.fileName,
            url: item.fullFilePath,
            id: item.id,
            filePath: item.filePath
          })
        })
        this.projectFileData.forEach((val, index) => {
          this.projectFileData[index].fileLists = files[val.moduleKey] || [];
          this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
        })

      }).catch((e) => {
        this.$message.error(e.toString());
      });
      this.$api.cgzh.copyright.getAll(this.objId).then(response => {
        this.objData = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    }
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
}

.t-form__item {
  margin-bottom: 6px
}

.step-form {
  padding: 0 24px;
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}
</style>
